<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for utils\utils.js</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../prettify.css" />
    <link rel="stylesheet" href="../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../index.html">all files</a> / <a href="index.html">utils/</a> utils.js
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">8.08% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>8/99</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">2.94% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>2/68</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">13.64% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>3/22</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">8.6% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>8/93</span>
      </div>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">export function trim(string) <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >    return (string || '').replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, '')</span>
}
&nbsp;
export function hasOwn(obj, key) <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >    return hasOwnProperty.call(obj, key)</span>
}
&nbsp;
// 判断是否为节点
export function isVNode(node) <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >    return typeof node === 'object' &amp;&amp; hasOwn(node, 'componentOptions')</span>
}
&nbsp;
// 节流函数
export function throttle(action, delay) <span class="fstat-no" title="function not covered" >{</span>
    let timeout = <span class="cstat-no" title="statement not covered" >null</span>
    let lastRun = <span class="cstat-no" title="statement not covered" >0</span>
<span class="cstat-no" title="statement not covered" >    return function() <span class="fstat-no" title="function not covered" >{</span></span>
<span class="cstat-no" title="statement not covered" >        if (timeout) {</span>
<span class="cstat-no" title="statement not covered" >            return</span>
        }
        let elapsed = <span class="cstat-no" title="statement not covered" >Date.now() - lastRun</span>
        let context = <span class="cstat-no" title="statement not covered" >this</span>
        let args = <span class="cstat-no" title="statement not covered" >Array.prototype.slice.call(arguments)</span>
        let runCallback = <span class="cstat-no" title="statement not covered" >function() <span class="fstat-no" title="function not covered" >{</span></span>
<span class="cstat-no" title="statement not covered" >            lastRun = Date.now()</span>
<span class="cstat-no" title="statement not covered" >            timeout = null</span>
<span class="cstat-no" title="statement not covered" >            action.apply(context, args)</span>
        }
<span class="cstat-no" title="statement not covered" >        if (elapsed &gt;= delay) {</span>
<span class="cstat-no" title="statement not covered" >            runCallback()</span>
        } else {
<span class="cstat-no" title="statement not covered" >            timeout = setTimeout(runCallback, delay)</span>
        }
    }
}
&nbsp;
// 异步加载图片
&nbsp;
export function loadImageAsync(src, resolve, reject) <span class="fstat-no" title="function not covered" >{</span>
    let image = <span class="cstat-no" title="statement not covered" >new Image()</span>
<span class="cstat-no" title="statement not covered" >    image.src = src</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >    image.onload = function() <span class="fstat-no" title="function not covered" >{</span></span>
<span class="cstat-no" title="statement not covered" >        resolve({</span>
            naturalHeight: image.naturalHeight, // 图片的原始大小与图片设置的大小无关
            naturalWidth: image.naturalWidth,
            src: image.src
        })
    }
&nbsp;
<span class="cstat-no" title="statement not covered" >    image.onerror = function(e) <span class="fstat-no" title="function not covered" >{</span></span>
<span class="cstat-no" title="statement not covered" >        reject(e)</span>
    }
}
// 注册及删除监听事件
const on = (function() {
    <span class="missing-if-branch" title="else path not taken" >E</span>if (document.addEventListener) {
        return function(el, event, handler) {
            el.addEventListener(event, handler, false)
        }
    } else <span class="cstat-no" title="statement not covered" >if (document.attachEvent) {</span>
<span class="cstat-no" title="statement not covered" >        return function(el, event, handler) <span class="fstat-no" title="function not covered" >{</span></span>
<span class="cstat-no" title="statement not covered" >            el.attachEvent('on' + event, handler)</span>
        }
    } else {
<span class="cstat-no" title="statement not covered" >        return function(el, event, handler) <span class="fstat-no" title="function not covered" >{</span></span>
<span class="cstat-no" title="statement not covered" >            el[on + 'event'] = handler</span>
        }
    }
})()
const off = (function() {
    <span class="missing-if-branch" title="else path not taken" >E</span>if (document.removeEventListener) {
        return function(el, event, handler) <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >            el.removeEventListener(event, handler, false)</span>
        }
    } else <span class="cstat-no" title="statement not covered" >if (document.detachEvent) {</span>
<span class="cstat-no" title="statement not covered" >        return function(el, event, handler) <span class="fstat-no" title="function not covered" >{</span></span>
<span class="cstat-no" title="statement not covered" >            el.detachEvent('on' + event, handler)</span>
        }
    } else {
<span class="cstat-no" title="statement not covered" >        return function(el, event, handler) <span class="fstat-no" title="function not covered" >{</span></span>
<span class="cstat-no" title="statement not covered" >            el[on + 'event'] = null</span>
        }
    }
})()
&nbsp;
// 注册函数
export const _ = {
    on,
    off
}
// 合并对象,并没有考虑深层次的情况
export function merge(obj = {}, ...args) <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >    for (let i = 0, len = args.length; i &lt; len; i++) {</span>
        let tempObj = <span class="cstat-no" title="statement not covered" >args[i]</span>
<span class="cstat-no" title="statement not covered" >        if (tempObj) {</span>
<span class="cstat-no" title="statement not covered" >            for (let prop in tempObj) {</span>
<span class="cstat-no" title="statement not covered" >                if (tempObj.hasOwnProperty(prop)) {</span>
<span class="cstat-no" title="statement not covered" >                    obj[prop] = tempObj[prop]</span>
                }
            }
        }
    }
<span class="cstat-no" title="statement not covered" >    return obj</span>
}
&nbsp;
export function contains(parentEl, el, container) <span class="fstat-no" title="function not covered" >{</span>
    // 第一个节点是否包含第二个节点
    // contains 方法支持情况：chrome+ firefox9+ ie5+, opera9.64+(估计从9.0+),safari5.1.7+
<span class="cstat-no" title="statement not covered" >    if (parentEl === el) {</span>
<span class="cstat-no" title="statement not covered" >        return true</span>
    }
<span class="cstat-no" title="statement not covered" >    if (!el || !el.nodeType || el.nodeType !== 1) {</span>
<span class="cstat-no" title="statement not covered" >        return false</span>
    }
<span class="cstat-no" title="statement not covered" >    if (parentEl.contains) {</span>
<span class="cstat-no" title="statement not covered" >        return parentEl.contains(el)</span>
    }
<span class="cstat-no" title="statement not covered" >    if (parentEl.compareDocumentPosition) {</span>
<span class="cstat-no" title="statement not covered" >        return !!(parentEl.compareDocumentPosition(el) &amp; 16)</span>
    }
    var prEl = <span class="cstat-no" title="statement not covered" >el.parentNode</span>
<span class="cstat-no" title="statement not covered" >    while (prEl &amp;&amp; prEl !== container) {</span>
<span class="cstat-no" title="statement not covered" >        if (prEl === parentEl) {</span>
<span class="cstat-no" title="statement not covered" >            return true</span>
        }
<span class="cstat-no" title="statement not covered" >        prEl = prEl.parentNode</span>
    }
<span class="cstat-no" title="statement not covered" >    return false</span>
}
export function hasClass(el, cls) <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >    if (!el || !cls) <span class="cstat-no" title="statement not covered" >return false</span></span>
<span class="cstat-no" title="statement not covered" >    if (cls.indexOf(' ') !== -1) <span class="cstat-no" title="statement not covered" >throw new Error('className should not contain space.')</span></span>
<span class="cstat-no" title="statement not covered" >    if (el.classList) {</span>
<span class="cstat-no" title="statement not covered" >        return el.classList.contains(cls)</span>
    } else {
<span class="cstat-no" title="statement not covered" >        return (' ' + el.className + ' ').indexOf(' ' + cls + ' ') &gt; -1</span>
    }
};
&nbsp;
export function addClass(el, cls) <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >    if (!el) <span class="cstat-no" title="statement not covered" >return</span></span>
    var curClass = <span class="cstat-no" title="statement not covered" >el.className</span>
    var classes = <span class="cstat-no" title="statement not covered" >(cls || '').split(' ')</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >    for (var i = 0, j = classes.length; i &lt; j; i++) {</span>
        var clsName = <span class="cstat-no" title="statement not covered" >classes[i]</span>
<span class="cstat-no" title="statement not covered" >        if (!clsName) <span class="cstat-no" title="statement not covered" >continue</span></span>
&nbsp;
<span class="cstat-no" title="statement not covered" >        if (el.classList) {</span>
<span class="cstat-no" title="statement not covered" >            el.classList.add(clsName)</span>
        } else <span class="cstat-no" title="statement not covered" >if (!hasClass(el, clsName)) {</span>
<span class="cstat-no" title="statement not covered" >            curClass += ' ' + clsName</span>
        }
    }
<span class="cstat-no" title="statement not covered" >    if (!el.classList) {</span>
<span class="cstat-no" title="statement not covered" >        el.className = curClass</span>
    }
};
&nbsp;
/* istanbul ignore next */
export function removeClass(el, cls) <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >    if (!el || !cls) <span class="cstat-no" title="statement not covered" >return</span></span>
    var classes = <span class="cstat-no" title="statement not covered" >cls.split(' ')</span>
    var curClass = <span class="cstat-no" title="statement not covered" >' ' + el.className + ' '</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >    for (var i = 0, j = classes.length; i &lt; j; i++) {</span>
        var clsName = <span class="cstat-no" title="statement not covered" >classes[i]</span>
<span class="cstat-no" title="statement not covered" >        if (!clsName) <span class="cstat-no" title="statement not covered" >continue</span></span>
&nbsp;
<span class="cstat-no" title="statement not covered" >        if (el.classList) {</span>
<span class="cstat-no" title="statement not covered" >            el.classList.remove(clsName)</span>
        } else <span class="cstat-no" title="statement not covered" >if (hasClass(el, clsName)) {</span>
<span class="cstat-no" title="statement not covered" >            curClass = curClass.replace(' ' + clsName + ' ', ' ')</span>
        }
    }
<span class="cstat-no" title="statement not covered" >    if (!el.classList) {</span>
<span class="cstat-no" title="statement not covered" >        el.className = trim(curClass)</span>
    }
}</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Feb 24 2019 15:08:50 GMT+0800 (中国标准时间)
</div>
</div>
<script src="../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../sorter.js"></script>
</body>
</html>
